<template>
  <div class="container">
    <div>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="选择日期：">
              <el-date-picker
                v-model="form.valueDay"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="班组：">
              <el-select v-model="teamValue" placeholder>
                <el-option
                  v-for="item in teamList"
                  :key="item.CLIENT_NAME"
                  :label="item.CLIENT_NAME"
                  :value="item.CLIENT_NAME"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float:left">
            <el-button size="mini" type="primary" @click="getlistdata">查 询</el-button>
            <el-button size="mini" type="success" @click="exportExcel">导 出</el-button>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table @cell-mouse-enter="cellMouseEnter" border v-loading="loading" :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)" highlight-current-row>
            <el-table-column  width="100" prop="TITLE" label="班组名称" align="center"></el-table-column>
            <el-table-column  width="100" prop="ROADNAME2" label="道路名称" align="center"></el-table-column>
            <el-table-column  width="300" prop="REMARKS2" label="作业人员" align="center"></el-table-column>
            <el-table-column prop="LRoadist" label="道路长度（米）" align="center"></el-table-column>
            <el-table-column prop="LWORK" label="累计作业长度（米）" align="center"></el-table-column>
            <el-table-column prop="LWORKBFB" label="百分比" align="center"></el-table-column>
            <el-table-column prop="NOWORKZHENG" label="正向未作业长度（米）" align="center"></el-table-column>
            <el-table-column prop="NOWORKZHENGBFB" label="百分比" align="center"></el-table-column>
            <el-table-column prop="NOWORKFAN" label="反向未作业长度（米）" align="center"></el-table-column>
            <el-table-column prop="NOWORKFANBFB" label="百分比" align="center"></el-table-column>
            <el-table-column prop="ZL" label="正向作业长度（米）" align="center"></el-table-column>
            <el-table-column prop="ZLBFB" label="百分比" align="center"></el-table-column>
            <el-table-column prop="FL" label="反向作业长度（米）" align="center"></el-table-column>
            <el-table-column prop="FLBFB" label="百分比" align="center"></el-table-column>
            <el-table-column prop="ZC" label="正向作业次数" align="center"></el-table-column>
            <el-table-column prop="FC" label="反向作业次数" align="center"></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      loading: false,
      form: {
        radioData: '日',
        valueDay: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        valueMonth: ''
      },
      teamList:[],
      teamValue:'',
      tableData: []

    }
  },
  created () {
    this.getTeamList();
  },
  methods: {
    async getTeamList () {
      const { data } = await this.$Http.get('/DataListCompany/GetCleanerGroupListApi?ClientNo=' + localStorage.getItem('CLIENT_NO'))
      this.teamList = data
      this.teamValue = data[0].CLIENT_NAME
      this.getlistdata()
    },
    async getlistdata () {
      this.loading = true;
      this.currentPage = 1;
      var clientStr = this.teamValue.split("-").join("")
      var url = 'DataListCompany/GetWorkerStatisticsYZApi?Date=' + this.form.valueDay + '&TeamName=' + clientStr
      console.log(url)
      const { data } = await this.$Http.get(url)
      this.tableData = data
      this.loading = false;
    },
    // 鼠标进入单元格显示其内容
    cellMouseEnter (row, column, cell, event) {
      cell.setAttribute('title', cell.innerText)
    },
    // 导出Excel
    exportExcel () {
      let excelName = '人工道路作业统计'
      const tHeader = ['班组名称', '道路名称', '作业人员', '道路长度（米）', '累计作业长度（米）', '百分比', '正向未作业长度（米）', '百分比', '反向未作业长度（米）', '百分比', '正向作业长度（米）', '百分比', '反向作业长度（米）', '百分比', '正向作业次数', '反向作业次数']
      const filterVal = ['TITLE', 'ROADNAME2', 'REMARKS2', 'LRoadist', 'LWORK', 'LWORKBFB', 'NOWORKZHENG', 'NOWORKZHENGBFB', 'NOWORKFAN', 'NOWORKFANBFB', 'ZL', 'ZLBFB', 'FL', 'FLBFB', 'ZC', 'FC']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>